<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="osgi,karaf,maven," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="概述前述文章介绍过Bndtools使得OSGi开发变得简单，高效。Bndtools适合在模块开发阶段，本文主要探讨在集成开发阶段如何快速搭建基于maven的自定义的karaf开发调试环境，对于想对karaf的配置环境进行自定义和裁剪的开发人员可以参考此方案。
Apache Karaf项目在基于OSGi的组件框架应用开发中为开发者和架构师提供了一个便利的基础运行和部署框架。通过Karaf的Featu">
<meta property="og:type" content="article">
<meta property="og:title" content="Apache Karaf构建动态模块化应用(5)--基于Maven快速搭建Karaf调试环境">
<meta property="og:url" content="http://chrisrc.me/2015/08/03/java-osgi-dynamic-app-with-karaf-dev/index.html">
<meta property="og:site_name" content="山中，山外与俯瞰">
<meta property="og:description" content="概述前述文章介绍过Bndtools使得OSGi开发变得简单，高效。Bndtools适合在模块开发阶段，本文主要探讨在集成开发阶段如何快速搭建基于maven的自定义的karaf开发调试环境，对于想对karaf的配置环境进行自定义和裁剪的开发人员可以参考此方案。
Apache Karaf项目在基于OSGi的组件框架应用开发中为开发者和架构师提供了一个便利的基础运行和部署框架。通过Karaf的Featu">
<meta property="og:image" content="http://chrisrc.me/images/java_osgi_karaf_2_features.png">
<meta property="og:image" content="http://chrisrc.me/images/java_osgi_karaf_2_kar.png">
<meta property="og:image" content="http://chrisrc.me/images/java_osgi_karaf_2_mvn_exec.png">
<meta property="og:image" content="http://chrisrc.me/images/java_osgi_karaf_2_netbeans.png">
<meta property="og:image" content="http://chrisrc.me/images/java_osgi_karaf_2_netbeans_2.png">
<meta property="og:image" content="http://chrisrc.me/images/java_osgi_karaf_2_netbeans_3.png">
<meta property="og:updated_time" content="2016-12-17T04:03:28.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Apache Karaf构建动态模块化应用(5)--基于Maven快速搭建Karaf调试环境">
<meta name="twitter:description" content="概述前述文章介绍过Bndtools使得OSGi开发变得简单，高效。Bndtools适合在模块开发阶段，本文主要探讨在集成开发阶段如何快速搭建基于maven的自定义的karaf开发调试环境，对于想对karaf的配置环境进行自定义和裁剪的开发人员可以参考此方案。
Apache Karaf项目在基于OSGi的组件框架应用开发中为开发者和架构师提供了一个便利的基础运行和部署框架。通过Karaf的Featu">
<meta name="twitter:image" content="http://chrisrc.me/images/java_osgi_karaf_2_features.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://chrisrc.me/2015/08/03/java-osgi-dynamic-app-with-karaf-dev/"/>





  <title> Apache Karaf构建动态模块化应用(5)--基于Maven快速搭建Karaf调试环境 | 山中，山外与俯瞰 </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">山中，山外与俯瞰</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">一次永不停止的探索之旅</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-dcos">
          <a href="/dcos" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-book"></i> <br />
            
            DC/OS
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="st-search-show-outputs">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <form class="site-search-form">
  <input type="text" id="st-search-input" class="st-search-input st-default-search-input" />
</form>

<script type="text/javascript">
  (function(w,d,t,u,n,s,e){w['SwiftypeObject']=n;w[n]=w[n]||function(){
    (w[n].q=w[n].q||[]).push(arguments);};s=d.createElement(t);
    e=d.getElementsByTagName(t)[0];s.async=1;s.src=u;e.parentNode.insertBefore(s,e);
  })(window,document,'script','//s.swiftypecdn.com/install/v2/st.js','_st');

  _st('install', 'R9GcmhBwxpsAGLNCsquZ','2.0.0');
</script>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="http://chrisrc.me/2015/08/03/java-osgi-dynamic-app-with-karaf-dev/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="chrisrc">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="/images/avatar.gif">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="山中，山外与俯瞰">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="山中，山外与俯瞰" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                Apache Karaf构建动态模块化应用(5)--基于Maven快速搭建Karaf调试环境
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2015-08-03T21:05:26+08:00">
                2015-08-03
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/OSGi/" itemprop="url" rel="index">
                    <span itemprop="name">OSGi</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <a href="/2015/08/03/java-osgi-dynamic-app-with-karaf-dev/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2015/08/03/java-osgi-dynamic-app-with-karaf-dev/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          

          
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="概述"><a href="#概述" class="headerlink" title="概述"></a>概述</h2><p>前述文章介绍过Bndtools使得OSGi开发变得简单，高效。Bndtools适合在模块开发阶段，本文主要探讨在集成开发阶段<br>如何快速搭建基于maven的自定义的karaf开发调试环境，对于想对karaf的配置环境进行自定义和裁剪的开发人员可以参考此方案。</p>
<p>Apache Karaf项目在基于OSGi的组件框架应用开发中为开发者和架构师提供了一个便利的基础运行和部署框架。通过Karaf的Feature定义及Kar打包，<br>开发者可以自由的定义OSGi Bundle的分组并按需定制细粒度的打包定义，在系统发布时，通过自由组合这些feature及kar，<br>可以快速发布针对性的产品或特定的发布包。</p>
<p>本文对之前写的一篇博客进行了简单整理，作为本系列的一部分。</p>
<h2 id="Karaf的Feature定义"><a href="#Karaf的Feature定义" class="headerlink" title="Karaf的Feature定义"></a>Karaf的Feature定义</h2><p>Karaf的Feature概念可以看作是一个系统的子系统实现。我们知道OSGi是基于Bundle和Service进行开发的，对于Bundle的粒度控制需要开发人员根据项目和系统功能凭借经验自己控制。在一个大的系统中，可能存在成百上千的Bundle，这么多Bundle如果聚合在一起，如何区分和维护将是一个巨大的挑战，这往往导致一些开发人员和架构师对OSGi模块化望而却步。</p>
<p>而通过Karaf的Feature定义，最小单元的OSGi Bundle可以根据功能部分聚合在一起形成一个功能Feature，多个Feature可以聚合在一起形成一个大的Feature，最终所有的OSGi Bundle就有序的组合起来，就可以形成清晰的，可重复利用的一个个功能Feature，实现系统的真正模块化开发和组件的重复利用。如下图所示：</p>
<p><img src="/images/java_osgi_karaf_2_features.png" alt="Karaf Feature"></p>
<h3 id="Karaf中的Feature"><a href="#Karaf中的Feature" class="headerlink" title="Karaf中的Feature"></a>Karaf中的Feature</h3><p>Karaf提供了丰富的Feature功能：</p>
<ul>
<li>framework-${KARAF_VERSION}-features.xml 定义了框架的Feature</li>
<li>standard-${KARAF_VERSION}-features.xml 定义了基础的Feature，包括：<ul>
<li>feature</li>
<li>shell</li>
<li>deployer</li>
<li>wrapper</li>
<li>obr</li>
<li>bundle</li>
<li>config</li>
<li>jaas</li>
<li>log</li>
<li>http</li>
<li>http-whiteboard</li>
<li>kar</li>
<li>webconsole</li>
<li>ssh</li>
<li>scr</li>
</ul>
</li>
<li>enterprise-${KARAF_VERSION}-features.xml 定义了支持J2EE应用的Feature<ul>
<li>transaction</li>
<li>jpa</li>
<li>openjpa</li>
<li>hibernate</li>
<li>eclipselink</li>
<li>jdbc</li>
<li>jms</li>
<li>jndi</li>
</ul>
</li>
<li>spring-${KARAF_VERSION}-features.xml 定义了Spring框架的支持</li>
<li>pax-web-features-${PAX_VERSION}-features.xml 定义了Pax Web的支持</li>
</ul>
<h3 id="Feature定义"><a href="#Feature定义" class="headerlink" title="Feature定义"></a>Feature定义</h3><p>现在，我们来看一个Karaf的Feature定义：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">feature</span> <span class="attr">name</span>=<span class="string">"spring"</span> <span class="attr">description</span>=<span class="string">"Spring 3.2.x support"</span> <span class="attr">version</span>=<span class="string">"3.2.11.RELEASE_1"</span>&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">bundle</span> <span class="attr">start-level</span>=<span class="string">"30"</span> <span class="attr">dependency</span>=<span class="string">"true"</span>&gt;</span>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.aopalliance/1.0_6<span class="tag">&lt;/<span class="name">bundle</span>&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">bundle</span> <span class="attr">start-level</span>=<span class="string">"30"</span>&gt;</span>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-core/3.2.11.RELEASE_1<span class="tag">&lt;/<span class="name">bundle</span>&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">bundle</span> <span class="attr">start-level</span>=<span class="string">"30"</span>&gt;</span>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-expression/3.2.11.RELEASE_1<span class="tag">&lt;/<span class="name">bundle</span>&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">bundle</span> <span class="attr">start-level</span>=<span class="string">"30"</span>&gt;</span>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-beans/3.2.11.RELEASE_1<span class="tag">&lt;/<span class="name">bundle</span>&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">bundle</span> <span class="attr">start-level</span>=<span class="string">"30"</span>&gt;</span>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-aop/3.2.11.RELEASE_1<span class="tag">&lt;/<span class="name">bundle</span>&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">bundle</span> <span class="attr">start-level</span>=<span class="string">"30"</span>&gt;</span>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-context/3.2.11.RELEASE_1<span class="tag">&lt;/<span class="name">bundle</span>&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">bundle</span> <span class="attr">start-level</span>=<span class="string">"30"</span>&gt;</span>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-context-support/3.2.11.RELEASE_1<span class="tag">&lt;/<span class="name">bundle</span>&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">conditional</span>&gt;</span></div><div class="line">            <span class="tag">&lt;<span class="name">condition</span>&gt;</span>deployer<span class="tag">&lt;/<span class="name">condition</span>&gt;</span></div><div class="line">            <span class="tag">&lt;<span class="name">bundle</span> <span class="attr">start-level</span>=<span class="string">"30"</span>&gt;</span>mvn:org.apache.karaf.deployer/org.apache.karaf.deployer.spring/4.0.0<span class="tag">&lt;/<span class="name">bundle</span>&gt;</span></div><div class="line">        <span class="tag">&lt;/<span class="name">conditional</span>&gt;</span></div><div class="line">    <span class="tag">&lt;/<span class="name">feature</span>&gt;</span></div></pre></td></tr></table></figure>
<p>此Feature定义了Spring 3.2.x版本，启用此feature，我们可以像SSH框架那样在OSGi Bundle中基于Spring进行开发，不存在迁移成本。在Karaf运行时，<br>如果安装了此Feature，系统会自动启动Feature中定义的Bundle集合。Bundle的查找顺序是：本地system目录下的Bundle—&gt;本地Maven仓库—&gt;远端Maven仓库。</p>
<h2 id="使用Karaf-Kar进行打包"><a href="#使用Karaf-Kar进行打包" class="headerlink" title="使用Karaf Kar进行打包"></a>使用Karaf Kar进行打包</h2><p>Karaf的Kar打包功能存在于karaf的karaf-maven-plugin插件中。通过此插件，karaf可以将featue定义中的所有bundle及其依赖打包到一个以.kar为后缀的压缩文件中，形成可发布的组件包。通过karaf-maven-plugin插件与maven打包相关的其它插件配合，用户可以自由定义发布包的结构。</p>
<p>对于多个已定义的kar分发包，通过maven依赖，可以在一个最终的maven发布工程中打包在一起，形成一个产品的发布包。如下图所示：</p>
<p><img src="/images/java_osgi_karaf_2_kar.png" alt="Karaf Kar"></p>
<p>关于Karaf的karaf-maven-plugin插件，请参考<a href="http://karaf.apache.org/manual/latest/developers-guide/karaf-maven-plugin.html" target="_blank" rel="external">官方文档</a></p>
<h2 id="搭建Karaf自定义调试环境"><a href="#搭建Karaf自定义调试环境" class="headerlink" title="搭建Karaf自定义调试环境"></a>搭建Karaf自定义调试环境</h2><p>下面简要讲述一下基于maven的Karaf自定义调试环境的搭建过程。</p>
<p>通常，基于OSGi的开发，推荐使用 <strong>Eclipse+Bndtools</strong> 的插件开发环境。对于集成调试，基于maven的OSGi插件开发<br>（Bndtools的<a href="https://github.com/bndtools/bnd/tree/master/bnd-maven-plugin" target="_blank" rel="external">bnd-maven-plugin</a>插件和Felix的<a href="http://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html" target="_blank" rel="external">maven-bundle-plugin</a>插件）同样方便、快速和高效，而且不受IDE开发环境的限制。</p>
<p>基于maven的OSGi开发，这里推荐使用Netbeans IDE（根据个人喜好），Netbeans对maven项目具有原生支持，可以自动解析maven的pom构建工程。</p>
<p>对于一个多模块的Maven OSGi项目(参考<a href="">karaf-osgi-app</a>)，构建一个<code>launcher</code>子模块，其pom.xml按如下定义：<br><figure class="highlight xml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div><div class="line">110</div><div class="line">111</div><div class="line">112</div><div class="line">113</div><div class="line">114</div><div class="line">115</div><div class="line">116</div><div class="line">117</div><div class="line">118</div><div class="line">119</div><div class="line">120</div></pre></td><td class="code"><pre><div class="line">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</div><div class="line"><span class="tag">&lt;<span class="name">project</span> <span class="attr">xmlns</span>=<span class="string">"http://maven.apache.org/POM/4.0.0"</span> <span class="attr">xmlns:xsi</span>=<span class="string">"http://www.w3.org/2001/XMLSchema-instance"</span> <span class="attr">xsi:schemaLocation</span>=<span class="string">"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">modelVersion</span>&gt;</span>4.0.0<span class="tag">&lt;/<span class="name">modelVersion</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">parent</span>&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>karaf<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>ossu.sandbox.karaf<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">version</span>&gt;</span>2.0.0-SNAPSHOT<span class="tag">&lt;/<span class="name">version</span>&gt;</span></div><div class="line">    <span class="tag">&lt;/<span class="name">parent</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>ossu.sandbox.karaf<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>karaf.launcher<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">packaging</span>&gt;</span>pom<span class="tag">&lt;/<span class="name">packaging</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">name</span>&gt;</span>Ossu Sandbox :: Karaf :: Launcher<span class="tag">&lt;/<span class="name">name</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">description</span>&gt;</span>Run karaf instance or debug karaf instance<span class="tag">&lt;/<span class="name">description</span>&gt;</span></div><div class="line"></div><div class="line">    <span class="tag">&lt;<span class="name">dependencies</span>&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></div><div class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.karaf.features<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></div><div class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>framework<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></div><div class="line">            <span class="tag">&lt;<span class="name">type</span>&gt;</span>kar<span class="tag">&lt;/<span class="name">type</span>&gt;</span></div><div class="line">        <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></div><div class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.karaf.features<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></div><div class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>standard<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></div><div class="line">            <span class="tag">&lt;<span class="name">classifier</span>&gt;</span>features<span class="tag">&lt;/<span class="name">classifier</span>&gt;</span></div><div class="line">            <span class="tag">&lt;<span class="name">type</span>&gt;</span>xml<span class="tag">&lt;/<span class="name">type</span>&gt;</span></div><div class="line">            <span class="tag">&lt;<span class="name">scope</span>&gt;</span>runtime<span class="tag">&lt;/<span class="name">scope</span>&gt;</span></div><div class="line">        <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></div><div class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.karaf.features<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></div><div class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></div><div class="line">            <span class="tag">&lt;<span class="name">classifier</span>&gt;</span>features<span class="tag">&lt;/<span class="name">classifier</span>&gt;</span></div><div class="line">            <span class="tag">&lt;<span class="name">type</span>&gt;</span>xml<span class="tag">&lt;/<span class="name">type</span>&gt;</span></div><div class="line">            <span class="tag">&lt;<span class="name">scope</span>&gt;</span>runtime<span class="tag">&lt;/<span class="name">scope</span>&gt;</span></div><div class="line">        <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></div><div class="line"></div><div class="line">        <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></div><div class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>ossu.sandbox.karaf<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></div><div class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>karaf.boilerplate.framework<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></div><div class="line">            <span class="tag">&lt;<span class="name">type</span>&gt;</span>kar<span class="tag">&lt;/<span class="name">type</span>&gt;</span></div><div class="line">            <span class="tag">&lt;<span class="name">version</span>&gt;</span>$&#123;project.version&#125;<span class="tag">&lt;/<span class="name">version</span>&gt;</span></div><div class="line">        <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></div><div class="line"></div><div class="line">    <span class="tag">&lt;/<span class="name">dependencies</span>&gt;</span></div><div class="line"></div><div class="line">    <span class="tag">&lt;<span class="name">build</span>&gt;</span></div><div class="line">        <span class="tag">&lt;<span class="name">plugins</span>&gt;</span></div><div class="line">            <span class="tag">&lt;<span class="name">plugin</span>&gt;</span></div><div class="line">                <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.karaf.tooling<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></div><div class="line">                <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>karaf-maven-plugin<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></div><div class="line">                <span class="tag">&lt;<span class="name">executions</span>&gt;</span></div><div class="line">                    <span class="tag">&lt;<span class="name">execution</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">id</span>&gt;</span>process-resources<span class="tag">&lt;/<span class="name">id</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">phase</span>&gt;</span>process-resources<span class="tag">&lt;/<span class="name">phase</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">goals</span>&gt;</span></div><div class="line">                            <span class="tag">&lt;<span class="name">goal</span>&gt;</span>install-kars<span class="tag">&lt;/<span class="name">goal</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;/<span class="name">goals</span>&gt;</span></div><div class="line">                    <span class="tag">&lt;/<span class="name">execution</span>&gt;</span></div><div class="line">                <span class="tag">&lt;/<span class="name">executions</span>&gt;</span></div><div class="line">                <span class="tag">&lt;<span class="name">configuration</span>&gt;</span></div><div class="line">                    <span class="tag">&lt;<span class="name">installedFeatures</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">feature</span>&gt;</span>wrapper<span class="tag">&lt;/<span class="name">feature</span>&gt;</span></div><div class="line">                    <span class="tag">&lt;/<span class="name">installedFeatures</span>&gt;</span></div><div class="line">                    <span class="tag">&lt;<span class="name">bootFeatures</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">feature</span>&gt;</span>framework<span class="tag">&lt;/<span class="name">feature</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">feature</span>&gt;</span>standard<span class="tag">&lt;/<span class="name">feature</span>&gt;</span></div><div class="line">                        <span class="comment">&lt;!--&lt;feature&gt;obr&lt;/feature&gt;--&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">feature</span>&gt;</span>region<span class="tag">&lt;/<span class="name">feature</span>&gt;</span></div><div class="line">                        <span class="comment">&lt;!--&lt;feature&gt;spring&lt;/feature&gt;--&gt;</span></div><div class="line">                    <span class="tag">&lt;/<span class="name">bootFeatures</span>&gt;</span></div><div class="line">                <span class="tag">&lt;/<span class="name">configuration</span>&gt;</span></div><div class="line">            <span class="tag">&lt;/<span class="name">plugin</span>&gt;</span></div><div class="line"></div><div class="line">            <span class="tag">&lt;<span class="name">plugin</span>&gt;</span></div><div class="line">                <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.codehaus.mojo<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></div><div class="line">                <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>exec-maven-plugin<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></div><div class="line">                <span class="tag">&lt;<span class="name">executions</span>&gt;</span></div><div class="line">                    <span class="tag">&lt;<span class="name">execution</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">goals</span>&gt;</span></div><div class="line">                            <span class="tag">&lt;<span class="name">goal</span>&gt;</span>exec<span class="tag">&lt;/<span class="name">goal</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;/<span class="name">goals</span>&gt;</span></div><div class="line">                    <span class="tag">&lt;/<span class="name">execution</span>&gt;</span></div><div class="line">                <span class="tag">&lt;/<span class="name">executions</span>&gt;</span></div><div class="line">                <span class="tag">&lt;<span class="name">configuration</span>&gt;</span></div><div class="line">                    <span class="tag">&lt;<span class="name">executable</span>&gt;</span>java<span class="tag">&lt;/<span class="name">executable</span>&gt;</span></div><div class="line">                    <span class="tag">&lt;<span class="name">workingDirectory</span>&gt;</span>$&#123;project.basedir&#125;/target/assembly<span class="tag">&lt;/<span class="name">workingDirectory</span>&gt;</span></div><div class="line">                    <span class="tag">&lt;<span class="name">arguments</span>&gt;</span></div><div class="line"></div><div class="line">                        <span class="tag">&lt;<span class="name">argument</span>&gt;</span>-classpath<span class="tag">&lt;/<span class="name">argument</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">argument</span>&gt;</span>$&#123;project.basedir&#125;/target/assembly/conf$&#123;path.separator&#125;$&#123;project.basedir&#125;/target/assembly/lib/karaf-jaas-boot.jar$&#123;path.separator&#125;$&#123;project.basedir&#125;/target/assembly/lib/karaf-jmx-boot.jar$&#123;path.separator&#125;$&#123;project.basedir&#125;/target/assembly/lib/karaf-org.osgi.core.jar$&#123;path.separator&#125;$&#123;project.basedir&#125;/target/assembly/lib/karaf.jar<span class="tag">&lt;/<span class="name">argument</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">argument</span>&gt;</span>-Xmx512m<span class="tag">&lt;/<span class="name">argument</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">argument</span>&gt;</span>-XX:MaxPermSize=512m<span class="tag">&lt;/<span class="name">argument</span>&gt;</span></div><div class="line"></div><div class="line">                        <span class="tag">&lt;<span class="name">argument</span>&gt;</span>-Dkaraf.startRemoteShell=true<span class="tag">&lt;/<span class="name">argument</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">argument</span>&gt;</span>-Djava.net.preferIPv4Stack=true<span class="tag">&lt;/<span class="name">argument</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">argument</span>&gt;</span>-Dderby.system.home=$&#123;project.basedir&#125;/target/assembly/data/derby<span class="tag">&lt;/<span class="name">argument</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">argument</span>&gt;</span>-Dderby.storage.fileSyncTransactionLog=true<span class="tag">&lt;/<span class="name">argument</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">argument</span>&gt;</span>-Dcom.sun.management.jmxremote<span class="tag">&lt;/<span class="name">argument</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">argument</span>&gt;</span>-Dkaraf.startLocalConsole=true<span class="tag">&lt;/<span class="name">argument</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">argument</span>&gt;</span>-Djline.WindowsTerminal.directConsole=false<span class="tag">&lt;/<span class="name">argument</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">argument</span>&gt;</span>-Dkaraf.home=$&#123;project.basedir&#125;/target/assembly<span class="tag">&lt;/<span class="name">argument</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">argument</span>&gt;</span>-Dkaraf.base=$&#123;project.basedir&#125;/target/assembly<span class="tag">&lt;/<span class="name">argument</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">argument</span>&gt;</span>-Dkaraf.etc=$&#123;project.basedir&#125;/target/assembly/etc<span class="tag">&lt;/<span class="name">argument</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">argument</span>&gt;</span>-Dkaraf.instances=$&#123;project.basedir&#125;/target/assembly/instances<span class="tag">&lt;/<span class="name">argument</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">argument</span>&gt;</span>-Djava.io.tmpdir=$&#123;project.basedir&#125;/target/assembly/data/tmp<span class="tag">&lt;/<span class="name">argument</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">argument</span>&gt;</span>-Djava.endorsed.dirs=$&#123;project.basedir&#125;/target/assembly/lib/endorsed<span class="tag">&lt;/<span class="name">argument</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">argument</span>&gt;</span>-Dkaraf.data=$&#123;project.basedir&#125;/target/assembly/data<span class="tag">&lt;/<span class="name">argument</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">argument</span>&gt;</span>-Djava.util.logging.config.file=$&#123;project.basedir&#125;/target/assembly/etc/java.util.logging.properties<span class="tag">&lt;/<span class="name">argument</span>&gt;</span></div><div class="line"></div><div class="line">                        <span class="comment">&lt;!-- Debug configuration --&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">argument</span>&gt;</span>-Xdebug<span class="tag">&lt;/<span class="name">argument</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">argument</span>&gt;</span>-Djava.compiler=NONE<span class="tag">&lt;/<span class="name">argument</span>&gt;</span></div><div class="line">                        <span class="tag">&lt;<span class="name">argument</span>&gt;</span>-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005<span class="tag">&lt;/<span class="name">argument</span>&gt;</span></div><div class="line"></div><div class="line">                        <span class="tag">&lt;<span class="name">argument</span>&gt;</span>org.apache.karaf.main.Main<span class="tag">&lt;/<span class="name">argument</span>&gt;</span></div><div class="line">                    <span class="tag">&lt;/<span class="name">arguments</span>&gt;</span></div><div class="line">                <span class="tag">&lt;/<span class="name">configuration</span>&gt;</span></div><div class="line">            <span class="tag">&lt;/<span class="name">plugin</span>&gt;</span></div><div class="line">        <span class="tag">&lt;/<span class="name">plugins</span>&gt;</span></div><div class="line">    <span class="tag">&lt;/<span class="name">build</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">project</span>&gt;</span></div></pre></td></tr></table></figure></p>
<p>通过这个pom定义，我们就可以在maven环境中启动karaf并进行调试。下面做一下详细说明：</p>
<h3 id="依赖部分"><a href="#依赖部分" class="headerlink" title="依赖部分"></a>依赖部分</h3><p>主要包括对karaf Framework kar的依赖，这是karaf框架的kar发布包，通过对其依赖，在运行时，Karaf的基础目录结构将被创建（位于该pom所在工程的target/assembly下）；<br>对karaf的<code>standard Feature</code>库和<code>spring feature</code>库进行依赖，通过对这两个feature库进行依赖，karaf在运行时可以知道到这两个feature库中查找具体的feature定义<br>对o<code>ssu.sandbox.karaf:karaf.boilerplate.framework</code>这个kar工程的依赖（这个kar是对karaf的具体裁剪，后面会讲到）。</p>
<h3 id="编译运行部分"><a href="#编译运行部分" class="headerlink" title="编译运行部分"></a>编译运行部分</h3><p>编译运行部分主要包括两个maven插件：karaf-maven-plugin和exec-maven-plugin。</p>
<ul>
<li><p>karaf-maven-plugin<br>此插件对依赖（jar、kar等）进行打包，生成发布kar包，并可以指定启动哪些feature</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">bootFeatures</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">feature</span>&gt;</span>framework<span class="tag">&lt;/<span class="name">feature</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">feature</span>&gt;</span>standard<span class="tag">&lt;/<span class="name">feature</span>&gt;</span></div><div class="line">  <span class="comment">&lt;!--&lt;feature&gt;obr&lt;/feature&gt;--&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">feature</span>&gt;</span>region<span class="tag">&lt;/<span class="name">feature</span>&gt;</span></div><div class="line">  <span class="comment">&lt;!--&lt;feature&gt;spring&lt;/feature&gt;--&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">bootFeatures</span>&gt;</span></div></pre></td></tr></table></figure>
</li>
<li><p>exec-maven-plugin</p>
</li>
</ul>
<p>此插件用于在maven工程中启动一个java虚拟机，此处主要是配置了karaf的启动参数并通过org.apache.karaf.main.Main入口启动Karaf。</p>
<h3 id="启动Karaf"><a href="#启动Karaf" class="headerlink" title="启动Karaf"></a>启动Karaf</h3><p>命令行环境下输入：</p>
<blockquote>
<p>mvn clean package exec:exec</p>
</blockquote>
<p>运行效果如下图所示：</p>
<p><img src="/images/java_osgi_karaf_2_mvn_exec.png" alt="Karaf Launcher"></p>
<p>在Netbeans IDE环境中启动执行，如下图所示，右键点击工程，在弹出菜单中选择定制——目标：</p>
<p><img src="/images/java_osgi_karaf_2_netbeans.png" alt="Karaf Netbeans"></p>
<p>在弹出窗口中输入：  </p>
<blockquote>
<p>clean package exec:exec</p>
</blockquote>
<p><img src="/images/java_osgi_karaf_2_netbeans_2.png" alt="Karaf Netbeans Run"></p>
<p>点击“确定”，执行效果如下图所示：</p>
<p><img src="/images/java_osgi_karaf_2_netbeans_3.png" alt="Karaf Netbeans Run"></p>
<h2 id="结论"><a href="#结论" class="headerlink" title="结论"></a>结论</h2><ul>
<li><p>限于篇幅，对于karaf的裁剪和自定义，将在后续文章中探讨。</p>
</li>
<li><p>karaf启动时开启了5005调试端口，可以连接上进行代码调试</p>
</li>
<li><p>此示例工程代码位于github的<a href="https://github.com/chrisrc/karaf-osgi-app" target="_blank" rel="external">karaf-osgi-app</a>。</p>
</li>
</ul>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/osgi/" rel="tag"># osgi</a>
          
            <a href="/tags/karaf/" rel="tag"># karaf</a>
          
            <a href="/tags/maven/" rel="tag"># maven</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2015/08/02/java-osgi-dynamic-app-with-karaf/" rel="next" title="Apache Karaf构建动态模块化应用(4)--了解Apache Karaf">
                <i class="fa fa-chevron-left"></i> Apache Karaf构建动态模块化应用(4)--了解Apache Karaf
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2015/08/04/java-osgi-dynamic-app-with-karaf-deploy/" rel="prev" title="Apache Karaf构建动态模块化应用(6)--Karaf离线打包发布">
                Apache Karaf构建动态模块化应用(6)--Karaf离线打包发布 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <div class="ds-share flat" data-thread-key="2015/08/03/java-osgi-dynamic-app-with-karaf-dev/"
     data-title="Apache Karaf构建动态模块化应用(5)--基于Maven快速搭建Karaf调试环境"
     data-content=""
     data-url="http://chrisrc.me/2015/08/03/java-osgi-dynamic-app-with-karaf-dev/">
  <div class="ds-share-inline">
    <ul  class="ds-share-icons-16">

      <li data-toggle="ds-share-icons-more"><a class="ds-more" href="javascript:void(0);">分享到：</a></li>
      <li><a class="ds-weibo" href="javascript:void(0);" data-service="weibo">微博</a></li>
      <li><a class="ds-qzone" href="javascript:void(0);" data-service="qzone">QQ空间</a></li>
      <li><a class="ds-qqt" href="javascript:void(0);" data-service="qqt">腾讯微博</a></li>
      <li><a class="ds-wechat" href="javascript:void(0);" data-service="wechat">微信</a></li>

    </ul>
    <div class="ds-share-icons-more">
    </div>
  </div>
</div>
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2015/08/03/java-osgi-dynamic-app-with-karaf-dev/"
           data-title="Apache Karaf构建动态模块化应用(5)--基于Maven快速搭建Karaf调试环境" data-url="http://chrisrc.me/2015/08/03/java-osgi-dynamic-app-with-karaf-dev/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.gif"
               alt="chrisrc" />
          <p class="site-author-name" itemprop="name">chrisrc</p>
          <p class="site-description motion-element" itemprop="description"></p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">69</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">21</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">162</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/christtrc" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://twitter.com/chrisrc" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
          
        </div>

        
        
          <div class="cc-license motion-element" itemprop="license">
            <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" target="_blank">
              <img src="/images/cc-by-nc-sa.svg" alt="Creative Commons" />
            </a>
          </div>
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#概述"><span class="nav-number">1.</span> <span class="nav-text">概述</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Karaf的Feature定义"><span class="nav-number">2.</span> <span class="nav-text">Karaf的Feature定义</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Karaf中的Feature"><span class="nav-number">2.1.</span> <span class="nav-text">Karaf中的Feature</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Feature定义"><span class="nav-number">2.2.</span> <span class="nav-text">Feature定义</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#使用Karaf-Kar进行打包"><span class="nav-number">3.</span> <span class="nav-text">使用Karaf Kar进行打包</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#搭建Karaf自定义调试环境"><span class="nav-number">4.</span> <span class="nav-text">搭建Karaf自定义调试环境</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#依赖部分"><span class="nav-number">4.1.</span> <span class="nav-text">依赖部分</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#编译运行部分"><span class="nav-number">4.2.</span> <span class="nav-text">编译运行部分</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#启动Karaf"><span class="nav-number">4.3.</span> <span class="nav-text">启动Karaf</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#结论"><span class="nav-number">5.</span> <span class="nav-text">结论</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2015 - 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">
     
      <a href="mailto:chrisrc@qq.com">chrisrc</a> 
    
  </span>
  <span class="author"> &nbsp; QQ: 58122705 </span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"chrisrc"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    
    <script src="/lib/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  








  
  

  

  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  
<script>
(function(){
   var src = (document.location.protocol == "http:") ? "http://js.passport.qihucdn.com/11.0.1.js?ed903ab05fbc5fa64d95e4bfbf3d3a04":"https://jspassport.ssl.qhimg.com/11.0.1.js?ed903ab05fbc5fa64d95e4bfbf3d3a04";
   document.write('<script src="' + src + '" id="sozz"><\/script>');
})();
</script>

  


</body>
</html>
